<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/14
 * Time: 23:16
 */

namespace app\api\controller;


use app\api\service\Payment;

class Callback
{
    //外网回调

    //支付宝
//    const APPID = '2018120562488348';
//    const PRIVATE_KEY = 'MIIEpAIBAAKCAQEA7TLBIBJPr1ILsW90fegpBbakxrXONLT5gc0jhvUw6+hfVuoTOjbCj+6940JkkLnJBaZJJfWbGSN1iSWi2hO5pTbHneWkOl+OIylHq8ATCoQippjB8a7Pbu4runlmHd2LYH2ZwuYvHuk84DQdWc3knGuLOcqCgQQIZ3rCj+IIjoE8bLpzGNOc2EE7bNtpdcVCDH44j1AEKj5SBSwTLrJiNDVSYF2slGtJEzSzss1uKFQ4wC6y4U+aho+RpSEOXydxb9SSx3nfW8LsDlsTzGsMa7+X8ZqRo/CBqyAGMIbvzyJaPu86LMyShm9TXK2obED0KQsVFXrldsjmepCZYEqxPQIDAQABAoIBAQCmp4hlXjg6eCzbB/ITHHDmIMN5EffFtHmxp04U3mT2+xcxW9kSh7L/qcAk0lsSDFae74xpbT0B1pYYPCdFjaJb4Dc0S0qt8MFPFwvSMmuucdRetOlfQ3FfAVwb8nu69BOfQeAsvcnRsBIjfLo6hJzhAfaaLhyvRQQaoHfe2/MjG3PqACVY5JLQnzyTvQw3W0axoQ2rF2ueX3kDvTGRIn+puidYxsjazhAa3LA6sA7uRx0zBiYHZQrGPMqWTENI/fgsKM18Bg/8Ak1xB9I7RsN25B6bI62mR19nKFa7ucJulRsk7i6j9/G0Bl6oz5/rVeaZcCW8wT8GSneqzR0M2VKJAoGBAPmYsTiWX33ARlN/DH/elcfnEaNtTZJ1NpziERFhhdwVOlDHeRaUB9NELRo6kT61q37lkNIRL/Jme6m9AKlQHostosyHA68Y3rjuwR6bBPglrLV1l3bAAQJjQL/Tvv7hxkn0QP5vTRtdsuNui/eXN+urIN1pbUI1AVXuWR3SgqZjAoGBAPNIogL2e+3IsvfsmSxN4O4VDtQRPybUsR0eRHa1RzSxaWpC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blSWNj2QOgi+K9aO3xIQsLvqLNOqQytVSzQ3mnWlhlJ2Pq38RLC0TCKPvILD6OkdxD6Uotaan2uXC/MCgYA77UvFDFGuq0teSfEMXJIuVFvqFdPz6qNkUBx8U08gUOMrYQ3bKgKDMrUDfX8kqUW28aDqZE25Bp5IaSK6TtPKQFuxlvOMRe8O+ohPWfLnbDsmILHgK8fT2xHAqlP6smIQPscCwcpqsu+0BkcXoyWsUG3I3B99FSF7+dbLBkgZkQKBgQCChGFmjLrOWk7/E3L6yv4kHe+AH/XwrGi+Dn7+38yTV3alxtpPce5Qz2Q/a/ie8+JWK9abESMz9MSYCaUnd74DMUCjb5MIZqAasnH+5q2Vlt0Tc2xmPjVMTOIYitggbwQuq77WgYX06xsDyvJsBO+L4nqPHd5F6n4hilVXrbS05A==';
    const PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtXfeoKsXiIWPkytw1aoTTaBV311fkhDCqaN9o4LcTX3eYGXQ1rfKdoaMo0zMDBzXN/OZqBI8apGdWAS5f6t2HZhb0nNaNgKY+J0wX99w9buWTKg4SUitkLC23XQclbeJmhN3+XpRu5sjLNsMv5sNWhaxCkJabJjH9z/SPWijHr45eUVNHtX+Q8mqCO4DIh8hXCQXW7ZIgRb+frDJy07ijcsR1ng981nZf7kkGV/VWC0ZZxS5eM/XJlH08tcYQ2Of0c0NdOtQT6YyHasWhHRzPwDSC7GGQoEsD41GIawLpuaKoDujqzRFA3cBD8MdOphDkm1mAExYrCN/Y1ysS+B23wIDAQAB';

    //app支付验证异步通知
    public function alipayApppayNotify_old(){
        $param = input('post.');
        Payment::alipayApppaySuccess($param);exit;
//        file_put_contents(RUNTIME_PATH.'/alipayApppayNotifyPost.txt',json_encode($_POST,JSON_UNESCAPED_UNICODE));exit;
        file_put_contents(RUNTIME_PATH.'/alipayApppayNotifyPost.txt',json_encode(input('post.'),JSON_UNESCAPED_UNICODE));
        import('alipay.aop.AopClient', EXTEND_PATH, '.php');
        $param = input('post.');
        $aop = new \AopClient;
        $aop->alipayrsaPublicKey = self::PUBLIC_KEY;
        $flag = $aop->rsaCheckV1($param, NULL, "RSA2");
        file_put_contents(RUNTIME_PATH.'/alipayApppayNotifyFlag.txt',$flag);
        if ($flag){
            //TODO 支付成功
            Payment::alipayApppaySuccess($param);
            echo 'SUCCESS';
        }else{
            //todo 支付失败
            echo '失败';
        }
    }

    //app支付验证异步通知
    public function alipayApppayNotify(){
        $param = input('post.');

        if ($param['trade_status'] == 'TRADE_SUCCESS'){
            //TODO 支付成功
            Payment::alipayApppaySuccess($param);
            echo 'SUCCESS';
        }else{
            //todo 支付失败
            echo '失败';
        }
    }
}